<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('超限记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                	<input type="hidden" name="tagid" id="treeId"/>
                
                    <div class="select-list">
                        <ul>
                          <li class="select-time">
					                  <p>时间：</p>
					                  <input type="text" class="time-input" id="startDate" placeholder="开始时间" name="startDate" th:field="*{data.startDate}"/>
					                  <span>-</span>
					                  <input type="text" class="time-input" id="endDate" placeholder="结束时间" name="endDate" th:field="*{data.endDate}"/>
					                </li>
													<li>
														测点：<input type="text" name="tagname" onclick="selectTagTree()" id="treeName" readonly="readonly"/>
													</li>
													<li>
					                  <p>轮值班组：</p>
					                  <select name="identify" th:with="team=${@dutyTeam.selectDutyTeamForEnable()}" style="width:100px">
					                      <option value="">所有</option>
					                      <option th:each="dutyTeam : ${team}" th:text="${dutyTeam.name}" th:value="${dutyTeam.identify}"></option>
					                  </select>
						              </li>
													 
													<li>
														<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;统计</a>
													    <a class="btn btn-warning btn-rounded btn-sm" onclick="resets()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
													</li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="overrun:record:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
	    var queryFlag = [[${@permission.hasPermi('overrun:dutycount:list')}]];
	    var prefix = ctx + "overrun/dutycount";

      $(function() {
    	  queryList();
      });

      // 查询列表
      function queryList() {
    	  var options = {
           url: prefix + "/list",
           exportUrl: prefix + "/export",
           modalName: "超限记录",
           columns: [{
               checkbox: true
           },
           {
               field : 'dutyid', 
               title : '轮值id',
               visible: false
           },
           {
               field : 'dutyname', 
               title : '轮值名称',
               width : 200,
               align: 'center'
           },
           {
               field : 'identify', 
               title : '轮值班组标识',
               visible: false
           },
           {
               field : 'teamname', 
               title : '轮值班组',
               width : 120,
               align: 'center'
           },
           {
               field : 'times', 
               title : '超限时长(分)',
               width : 120,
               align: 'center'
           },
           {
               field : 'counts', 
               title : '超限次数',
               width : 120,
               align: 'center'
           },
           {
           	title: '操作',
         	  width : 150,
             align: 'center',
             formatter: function(value, row, index) {
                 var actions = [];
                 actions.push('<a class="btn btn-success btn-xs ' + queryFlag + '" href="javascript:void(0)" onclick="viewTagDetail(\'' + row.dutyid + '\',\'' + row.identify + '\')"><i class="fa fa-edit"></i>测点明细</a> ');
                 actions.push('<a class="btn btn-primary btn-xs ' + queryFlag + '" href="javascript:void(0)" onclick="viewDetail(\'' + row.dutyid + '\',\'' + row.identify + '\')"><i class="fa fa-remove"></i>记录明细</a>');
                 return actions.join('');
             }
           }]
        };
        $.table.init(options);
      }

			// 重置事件
			function resets() {
				$("#treeId").val("");
				$("#treeName").val("");
				$.form.reset();
			}
		
			// 明细操作
			function viewTagDetail(dutyid,identify) {
				var params = "startDate="+$("#startDate").val()+"&endDate="+$("#endDate").val()+"&tagid="+$("#treeId").val()+"&tagname="+$("#treeName").val();
				params = params + "&dutyid=" + dutyid + "&identify=" + identify;
				
				var url = ctx + 'overrun/tagcount/toCountdtl?'+params;
				$.modal.openTab("超限统计测点明细", url);
			}
			
			// 记录明细操作
			function viewDetail(dutyid,identify) {
				var params = "startDate="+$("#startDate").val()+"&endDate="+$("#endDate").val()+"&tagid="+$("#treeId").val()+"&tagname="+$("#treeName").val();
				params = params + "&dutyid=" + dutyid + "&identify=" + identify;
				
				var url = ctx + 'overrun/record/toDetail?' + params;
				$.modal.openTab("超限记录明细", url);
			}

			// 选择测点树
			function selectTagTree() {
				var tagid = $.common.isEmpty($("#treeId").val()) ? "0" : $("#treeId").val();
	      var url = ctx + "tag/config/selectTagTree/" + tagid;
		    var options = {
					title: '选择测点',
					width: "380",
					url: url,
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			}
			// 选择测点确定按钮
			function doSubmit(index, layero){
				var tree = layero.find("iframe")[0].contentWindow.$._tree;
				if ($.tree.notAllowParents(tree)) {
	    			var body = layer.getChildFrame('body', index);
	    			$("#treeId").val(body.find('#treeId').val());
	    			$("#treeName").val(body.find('#treeName').val());
	    			layer.close(index);
				}
			}

    </script>
</body>
</html>